<?php if (!defined("MAIN_DIR")) die("<h1>Access denied</h1>");

$project_id = $this->POST("id");
sleep(1);
$query = "select `P`.`name`,`P`.`alias`,`U`.`user_id`,`U`.`login`
	from `projects` as `P`
	left join `users` as `U`
	on `P`.`creator_id` = `U`.`user_id`
	where `project_id` = '$project_id'
	group by `P`.`project_id` limit 1";

$project_info = $this->db->getRow($query);
if ($project_info) {

	$response = "{";
	$response .= '"name":"'.$project_info['name'].'","alias":"'.$project_info['alias'].'","user_id":"'.$project_info['user_id'].'","login":"'.$project_info['login'].'"';
	
	$record_type = array("bug"=>0,"addition"=>0,"change"=>0);
	$record_status = array("complete"=>0,"process"=>0,"query"=>0,"rejected"=>0,"new"=>0);
	
	$query = "select `type`,`status` from `records` where `project_id` = '$project_id' and `parent_id` = '0' order by `record_id`";
	$records = $this->db->getTable($query);
	
	foreach ($records as $record){
		$record_type[$record['type']]++;
		$record_status[$record['status']]++;
	}
	
	$response .= ',"bug":'.$record_type['bug'].',"addition":'.$record_type['addition'].',"change":'.$record_type['change'].',"complete":'.$record_status['complete'].',"process":'.$record_status['process'].',"query":'.$record_status['query'].',"rejected":'.$record_status['rejected'].',"new":'.$record_status['new'];
	
	echo $response .= "}";
} else {
	echo "null";
}

?>